import { ForwardRefRenderFunction, memo, useImperativeHandle, forwardRef } from 'react'
import { Space, Button } from 'antd'
import { useTypeStore } from '@/store/useOperationDataItem'
import { HsAdminDataItemExample } from '@hs-admin/components'

interface Props {
  dataItem: any
  back: () => void
  finish: (params: any) => void
}

const Step3: ForwardRefRenderFunction<unknown, Props> = (props: Props, ref: any) => {
  const { dataItem, back, finish } = props
  let { id } = dataItem

  const data_item_id = useTypeStore((state) => state.data_item_id)
  if (!id && data_item_id) {
    id = data_item_id
  }
  const data_item_infor = useTypeStore((state) => state.data_item_infor)

  useImperativeHandle(
    ref,
    () => {
      return {}
    },
    []
  )

  return (
    <>
      <HsAdminDataItemExample dataItemId={id} />
      <Space className="flex justify-end">
        <Button onClick={back}>取消</Button>
        <Button type="primary" onClick={() => finish(data_item_infor)}>
          确定
        </Button>
      </Space>
    </>
  )
}

export default memo(forwardRef(Step3))
